﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.person_info
{
    public partial class group_edit : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int groupId = (Request.QueryString["group_id"] != null) ? int.Parse(Request.QueryString["group_id"].ToString()) : 0;
                this.ViewState["GroupId"] = groupId;
                DataTable table = new GroupDao().SelectByGroupId(base.Conn, base.User.Identity.Name, groupId);
                if (table.Rows.Count > 0)
                {
                    this.txtGroupName.Text = table.Rows[0]["GroupName"].ToString();
                    this.txtGroupNo.Text = table.Rows[0]["GroupNo"].ToString();
                }
                else
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无此用户组", "group.aspx");
                }
            }
            if (this.Page.IsPostBack)
            {
                GroupDao dao = new GroupDao();
                GroupData data = new GroupData();
                data.GroupId = Convert.ToInt32(this.ViewState["GroupId"].ToString());
                data.UserId = base.User.Identity.Name;
                data.Name = this.txtGroupName.Text;
                data.GroupNo = this.txtGroupNo.Text;
                dao.Update(base.Conn, data);
                base.CloseConn();
                Response.Redirect("group.aspx");
            }
        } 

    }
}
